package com.zhangchuchu.neohealth.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.zhangchuchu.neohealth.common.R;
import com.zhangchuchu.neohealth.entity.UserProfile;
import com.zhangchuchu.neohealth.service.UserProfileService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.io.Serializable;
import java.util.List;

/**
 * 用户个人信息表(UserProfile)控制层
 *
 * @author makejava
 * @since 2025-04-16 09:35:56
 */
@RestController
@RequestMapping("/userProfile")
public class UserProfileController {
    @Resource
    private UserProfileService userProfileService;

    /**
     * 查询所有数据（不分页）
     */
    @GetMapping("/getList")
    public R<List<UserProfile>> selectList() {
        return R.success(userProfileService.list());
    }

    /**
     * 分页查询
     */
    @GetMapping
    public R<Page<UserProfile>> selectAll(Page<UserProfile> page, UserProfile userProfile) {
        return R.success(userProfileService.page(page, new QueryWrapper<>(userProfile)));
    }

    /**
     * 通过主键查询单条数据
     */
    @GetMapping("{id}")
    public R<UserProfile> selectOne(@PathVariable Serializable id) {
        return R.success(userProfileService.getById(id));
    }

    /**
     * 新增数据
     */
    @PostMapping
    public R<Boolean> insert(@RequestBody UserProfile userProfile) {
        return R.success(userProfileService.save(userProfile));
    }

    /**
     * 修改数据
     */
    @PutMapping
    public R<Boolean> update(@RequestBody UserProfile userProfile) {
        return R.success(userProfileService.updateById(userProfile));
    }

    /**
     * 删除数据（批量）
     */
    @DeleteMapping
    public R<Boolean> delete(@RequestParam("idList") List<Integer> idList) {
        return R.success(userProfileService.removeByIds(idList));
    }

}
